package longestCommonPrefix;

import java.util.Arrays;
import java.util.Comparator;

public class Solution {
    public String longestCommonPrefix(String[] strs) {
        // 暴力
        // 枚举所有可能的长度
        int maxLen = 0;
        for (String s: strs) {
            maxLen = Math.min(s.length(),maxLen);
        }
        StringBuilder ans = new StringBuilder();
        for (int len = 0; len < maxLen; len++) {
            char c = strs[0].charAt(len);
            for (String s: strs) {
                if(s.charAt(len) != c) {
                    return ans.toString();
                }
            }
            ans.append(c);
        }
        return ans.toString();
    }
}
